#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<map>
#include<string>
#include<vector>
using namespace std;
class Solution {
public:
    vector<int> findAnagrams(string s, string p) {
        map<char, int> mp;
        for (auto& e : p) {
            mp[e]++;
        }
        map<char, int> ret;
        vector<int> ret1;
        int count = 0;
        for (int left = 0, right = 0; right < s.size(); right++) {
            ret[s[right]]++;

            if (mp.find(s[right]) != mp.end() && ret[s[right]] <= mp[s[right]])
                count++;

            if (right - left + 1 > p.size()) {

                if (mp.find(s[left]) != mp.end() && ret[s[left]] <= mp[s[left]])
                    count--;
                ret[s[left]]--;
                if (ret[s[left]] == 0)
                    ret.erase(s[left]);
                left++;
            }
            if (count == p.size())
                ret1.push_back(left);
        }
        return ret1;
    }
};
int main()
{
    findAnagrams("baa", "aa");
}